﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MyRoguelike.Game.Objects
{
    class GameObject
    {
        private bool _isEnemy = false;
        private bool _isAlly = false;

        protected Level _level;

        public Level Level
        {
            get { return _level; }
        }

        public bool IsEnemy
        {
            get { return _isEnemy; } 
            set
            {
                _isAlly = (value) ? false : true;

                _isEnemy = value;
            }
        }

        public bool IsAlly
        {
            get { return _isAlly; }
            set
            {
                _isEnemy = (value) ? false : true;

                _isAlly = value;
            }
        }

        public bool IsNeutral
        {
            get { return !(_isEnemy || _isAlly); }
        }

        public bool IsCreature { get; set; }

        public bool IsPlayer { get; set; }

        // Texture for object
        public Texture2D Texture { get; set; }


        public GameObject(Level level)
        {
            _level = level;
            IsEnemy = false;
        }

        public Vector2 Position { get; set; }


        public virtual void Update(GameTime gameTime) { }

        public virtual void Draw(SpriteBatch spriteBatch)
        {
            if (Texture != null)
            {
                Vector2 origin = new Vector2(Texture.Width / 2, Texture.Height / 2);

                spriteBatch.Draw(Texture,
                                 (Position - _level.Camera.GetDrawOffset()),
                                 null, 
                                 Color.White * (1 - _level.GetFogOfWarFromObjectPos(Position)), 
                                 0f, origin, 1f, SpriteEffects.None, 0f);

                
            }
        }

        public virtual void Step() { }

        /// <summary>
        /// Call when was a collision with other object
        /// </summary>
        /// <param name="other">Other GameObject</param>
        /// <returns>If movement is allowed that returns 'true'</returns>
        public virtual bool OnCollision(GameObject other)
        {
            return true;
        }
    }
}
